﻿<!-- 右侧固定导航栏 -->
<template>
  <div class="rightlistBox">
    <section>
      <div v-if="!isLoading" v-for="item in blogrightList" :key="item.id">
        <div class="r1-head">
          <img :src="item.blogimage" alt="Blog Image" />
        </div>
        <div class="r1-body">
          <p class="blogcreate">{{ item.blogcreate }}</p>
          <p>{{ item.blogtext }},</p>
          <p>{{ item.blogtexttwo }}。</p>
        </div>
      </div>
      <el-skeleton :rows="5" v-else animated />

      <div class="articleTaol" v-if="!isLoading">
        <p>
          <svg class="icon huiyuan" aria-hidden="true">
            <use xlink:href="#icon-wenzhang"></use>
          </svg>
          文章：<span>{{ articleCount }}</span>
        </p>
        <p>
          <svg class="icon huiyuan" aria-hidden="true">
            <use xlink:href="#icon-biaoqian"></use>
          </svg>
          标签：<span>{{ tagCount }}</span>
        </p>
        <p>
          <svg class="icon huiyuan" aria-hidden="true">
            <use xlink:href="#icon-lianjie"></use>
          </svg>
          友链：<span>{{ linkCount }}</span>
        </p>
      </div>
      <el-skeleton :rows="3" animated v-else />

      <div class="announcement" v-if="!isLoading" v-for="item in blogrightList">
        <svg
          class="icon huiyuan"
          aria-hidden="true"
          style="width: 14px; height: 14px"
        >
          <use xlink:href="#icon-gonggao"></use>
        </svg>
        <span>新功能发布：</span>
        <span class="announcementtext">
          {{ item.announcement }}
        </span>
      </div>
      <el-skeleton :rows="1" animated v-else />
    </section>
    <section class="rs4">
      <h2 class="ui label">
        <svg class="icon huiyuan" aria-hidden="true">
          <use xlink:href="#icon-remen"></use>
        </svg>
        热门文章
      </h2>
      <ol>
        <li
          v-if="!isLoading"
          v-for="(item, index) in rankedBrowseList"
          :key="'browseList' + index"
        >
          <div class="rank">{{ index + 1 }}</div>
          <a :href="'#/DetailArticle?aid=' + item.id" target="_blank">{{
            item.title
          }}</a>
          <i class="el-icon-view" style="color: crimson"
            ><span class="viewCount">{{ item.viewCount }} 次浏览</span></i
          >
        </li>
        <el-skeleton :rows="3" animated v-else />
      </ol>
    </section>
    <section class="rs4">
      <h2 class="ui label">
        <svg class="icon huiyuan" aria-hidden="true">
          <use xlink:href="#icon-zuixingengxin"></use>
        </svg>
        最新发布
      </h2>
      <ul>
        <li
          v-if="!isLoading"
          v-for="(item, index) in newBrowseList"
          :key="'newBrowseList' + index"
        >
          <div class="rank">{{ index + 1 }}</div>
          <a :href="'#/DetailArticle?aid=' + item.id" target="_blank">{{
            item.title
          }}</a>
          <i class="el-icon-time" style="color: rgb(139, 139, 139)"
            ><span style="color: rgb(139, 139, 139)">{{
              formatDate(item.createTime)
            }}</span></i
          >
        </li>
        <el-skeleton :rows="3" animated v-else />
      </ul>
    </section>
    <!-- 右侧上滑小图片 -->
    <div class="scroll-to-top" v-if="showButton" @click="scrollToTop">
      <i
        ><svg
          class="icon shangsheng"
          aria-hidden="true"
          style="width: 60px; height: 60px"
        >
          <use xlink:href="#icon-shangsheng"></use></svg
      ></i>
    </div>
  </div>
</template>


<script>
import { hotArticleList, newArticleList, getToal } from "../api/article";
import { getBlogrightList } from "../api/rightblog";
export default {
  data() {
    //选项 / 数据
    return {
      articleCount: "",
      isLoading: true,
      linkCount: "",
      tagCount: "",
      fixDo: false,
      loveme: false,
      showButton: false,
      browseList: "", //热门文章 浏览量最多
      newBrowseList: "",
      artCommentList: "", //最新评论
      blogrightList: [],
    };
  },
  methods: {
    getRight() {
      getBlogrightList().then((response) => {
        this.blogrightList = response; // 将响应的数据赋值给blogrightList
        // console.log(this.blogrightList);
        setTimeout(() => {
          this.isLoading = false;
        }, 2000);
      });
    },

    //事件处理器
    toTopfun: function (e) {
      var that = this;
      this.gotoTop = false;
      this.going = true;
      var timer = setInterval(function () {
        //获取滚动条距离顶部高度
        var osTop =
          document.documentElement.scrollTop || document.body.scrollTop;
        var ispeed = Math.floor(-osTop / 7);
        document.documentElement.scrollTop = document.body.scrollTop =
          osTop + ispeed;
        //到达顶部，清除定时器
        if (osTop == 0) {
          that.going = false;
          clearInterval(timer);
          timer = null;
        }
      }, 30);
    },
    getHotArticleList() {
      hotArticleList().then((response) => {
        this.browseList = response;
      });
    },
    getNewArticleList() {
      newArticleList().then((response) => {
        this.newBrowseList = response;
      });
    },
    getToalArticle() {
      getToal().then((response) => {
        //console.log(response)
        (this.articleCount = response.articleCount),
          (this.linkCount = response.linkCount),
          (this.tagCount = response.tagCount);
      });
    },

    handleScroll() {
      // 根据滚动条位置判断是否显示回到顶部按钮
      this.showButton = window.pageYOffset > 200;
    },
    scrollToTop() {
      // 使用 window.scrollTo() 方法滚动页面到顶部
      window.scrollTo({
        top: 0,
        behavior: "smooth",
      });
    },
    formatDate(time) {
      let date = new Date(time);
      return (
        date.getFullYear() +
        "年" +
        (date.getMonth() + 1) +
        "月" +
        date.getDate() +
        "日"
      );
    },
  },
  components: {
    //定义组件
  },
  computed: {
    rankedBrowseList() {
      const arr = this.browseList.slice();
      if (arr.length > 0) {
        return arr.sort((a, b) => b.viewCount - a.viewCount);
      } else {
        return [];
      }
    },
  },

  created() {
    //生命周期函数
    var that = this;
    window.onscroll = function () {
      var t = document.documentElement.scrollTop || document.body.scrollTop;
      // console.log(t);
      if (!that.going) {
        if (t > 600) {
          that.gotoTop = true;
        } else {
          that.gotoTop = false;
        }
      }
      if (t > 1200) {
        that.fixDo = true;
      } else {
        that.fixDo = false;
      }
    };
    //查询浏览量最多的10篇文章数据
    this.getHotArticleList();
    this.getNewArticleList();
    this.getToalArticle();
    this.getRight();
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },
  beforeDestroy() {
    window.removeEventListener("scroll", this.handleScroll);
  },
};
</script>

<style lang="less">
.announcement {
  text-align: center;
}

.announcement .announcementtext {
  font-size: 1em;
  color: #e69328; /* 设置文本颜色，这里使用蓝色 */
  text-decoration: underline; /* 添加下划线文本装饰 */
}
.blogcreate {
  color: #007bff !important; /* 设置文字颜色为红色 */
  font-size: 18px; /* 设置文字大小为18像素 */
  font-weight: bold; /* 设置文字加粗 */
  /* 添加其他你想要的样式 */
}
.ui.label {
  background-color: #ff6f61; /* 背景颜色 */
  color: #fff; /* 字体颜色 */
  padding: 8px 16px; /* 内边距 */
  border-radius: 5px; /* 圆角 */
  font-size: 18px; /* 字体大小 */
  display: inline-block; /* 行内块元素 */
  margin-bottom: 16px; /* 底部间距 */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 阴影 */
}

.icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}

.rank {
  display: inline-block;
  width: 30px;
  height: 30px;
  line-height: 30px;
  font-size: 16px;
  text-align: center;
  border-radius: 50%;
  background: linear-gradient(to right, #ff416c, #ff4b2b);
  color: #fff;
  margin-right: 10px;
  margin-bottom: 5px;
  font-weight: bold;
  box-shadow: 0 8px 20px 0 rgba(255, 65, 108, 0.5),
    0 6px 6px 0 rgba(255, 65, 108, 0.4);
}

.viewCount {
  font-size: 14px;
  color: #666;
  margin-left: 10px;
}

//右边的字
.articleTaol {
  text-align: center;
  display: flex;
  justify-content: space-between;
  position: relative; /* 设置 articleTaol 元素为相对定位 */
}
.articleTaol::before {
  /* 添加一个伪元素 */
  content: "";
  position: absolute; /* 将伪元素改为绝对定位 */
  top: 0;
  left: 0;
  width: 100%;
  height: 1px; /* 伪元素高度为 1px */
  background-color: #ccc; /* 设置伪元素颜色 */
  z-index: 1; /* 将伪元素z-index属性值设置为1，使其在p元素的下面 */
}
.articleTaol p {
  padding: 25px 0 25px 0;
  font-size: 25px;
  flex-basis: 30%;
  flex-grow: 1;
  color: #32325d;
  z-index: 2; /* 将p元素的z-index属性值设置为2，使其在伪元素的上面 */
  span {
    font-size: 30px;
    font-weight: bold;
  }
}

.scroll-to-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.3s ease;
}
.scroll-to-top:hover {
  opacity: 1;
}

.rightlistBox {
  position: relative;
}
.rightlistBox section {
  transition: all 0.2s linear;
  position: relative;
  background: #fff;
  padding: 15px;
  margin-bottom: 20px;
  border-radius: 5px;
}
.rightlistBox section:hover {
  transform: translate(0, -2px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
}
.rightlistBox .r1-head {
  text-align: center;
  border-radius: 4px 4px 0 0;
  text-align: center;
  position: relative;

  img {
    width: 100%;
  }
}

.rightlistBox .r1-head h1 {
  position: absolute;
  bottom: 5px;
  margin: 0 0 0 -65px;
  font-size: 20px;
  letter-spacing: 0.5px;
  color: #fff;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.7);
  font-weight: 700;
  width: 130px;
  left: 50%;
}
.rightlistBox .r1-head h1 span {
  opacity: 0.3;
}
.rightlistBox .r1-body p {
  font-size: 18px;
  margin: 5px 0 8px 0;
  // font-weight: 700;
  text-align: center;
  color: #000000;
}
.rightlistBox .r1-body .catch-me {
  text-align: center;
}
.rightlistBox .r1-body .catch-me a {
  display: inline-block;
  margin-bottom: 7px;
  position: relative;
  text-decoration: none;
}
.rightlistBox .r1-body .catch-me a:hover i {
  color: #fff;
  background: #f4692c;
}
.rightlistBox .r1-body .catch-me a i {
  display: inline-block;
  font-size: 18px;
  width: 42px;
  height: 42px;
  line-height: 42px;
  border-radius: 42px;
  color: rgba(0, 0, 0, 0.5);
  background: rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease-in-out;
  font-style: normal;
  margin: 0 3.2px;
}

/*************do you like me*******************/
.rightlistBox .rs2 {
  /*padding:10px 0 4px 0;*/
  min-height: 100px;
}
.rightlistBox .rs2.fixed {
  position: fixed;
  top: 40px;
  width: 22%;
}
.rightlistBox .rs2 p {
  color: #df2050;
  cursor: pointer;
  font-size: 20px;
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  margin-top: 10px;
  font-weight: 500;
}
.rightlistBox .rs2 div {
  color: #df2050;
  cursor: pointer;
  text-align: center;
  font-size: 40px;
  position: absolute;
  width: 100%;
  height: 100px;
  line-height: 100px;
  left: 0;
  top: 30px;
}
.rightlistBox .rs2 div i.heart {
  display: inline-block;
  text-align: center;
  width: 100px;
  height: 100px;
  margin-left: -20px;
  margin-top: -5px;
  // background: url(../../static/img/heart.png) no-repeat;
  background-position: 0 0;
  cursor: pointer;
  -webkit-transition: background-position 1s steps(28);
  transition: background-position 1s steps(28);
  -webkit-transition-duration: 0s;
  transition-duration: 0s;
  vertical-align: middle;
}
.rightlistBox .rs2 div i.heart:hover {
  transform: scale(1.15);
  -webkit-transform: scale(1.15);
}
.rightlistBox .rs2 div i.heart.active {
  -webkit-transition-duration: 1s;
  transition-duration: 1s;
  background-position: -2800px 0;
}
.rightlistBox .rs2 div span {
  margin-left: -30px;
}
/**********排队来说*************/
.rightlistBox .rs3 .rs3-item {
  font-size: 13px;
  line-height: 20px;
}
.rightlistBox .rs3 .rs3-item a {
  display: block;
  padding: 5px;
  transition: all 0.3s ease-out;
  border-bottom: 1px solid #ddd;
  margin: 5px 0;
}
.rightlistBox .rs3 .rs3-item a:hover {
  background: rgba(230, 244, 250, 0.5);
  border-radius: 5px;
}
.rightlistBox .rs3 .rs3-photo {
  float: left;
}
.rightlistBox .rs3 .rs3-photo img {
  border-radius: 50%;
  width: 32px;
  height: 32px;
  object-fit: cover;
}
.rightlistBox .rs3 .rs3-inner {
  margin-left: 40px;
}
.rightlistBox .rs3 .rs3-inner .rs3-author {
  font-weight: 700;
}
.rightlistBox .rs3 .rs3-inner .rs3-text {
  font-size: 12px;
  text-align: justify;
}
.rightlistBox .rs3 .rs3-item:last-child a {
  border-bottom: none;
}
/************排队看这些***************/
.rightlistBox .rs4 li {
  padding: 8px 0;
  text-align: justify;
}

.rightlistBox .rs4 li a:hover {
  color: #db8412;
}

/*回到顶部*/
/*返回到顶部*/
</style>
